package com.nbjtjc.safe.service.edu;

import cn.hutool.core.util.ObjectUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.nbjtjc.safe.bean.Result;
import com.nbjtjc.safe.mapper.edu.EduDailyUserEvaluateMapper;
import com.nbjtjc.safe.model.edu.EduDailyUserEvaluate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EduDailyUserEvaluateService {
	@Autowired
	  private EduDailyUserEvaluateMapper eduDailyUserEvaluateMapper;
		
	  public Result add(EduDailyUserEvaluate eduDailyUserEvaluate){
		        Result result=new Result();
		        if(ObjectUtil.isNull(eduDailyUserEvaluate)
		        		||ObjectUtil.isNull(eduDailyUserEvaluate.getEduDailyInfoId())
//		        		||ObjectUtil.isNull(eduDailyUserEvaluate.getReqInvestId())
		        		||ObjectUtil.isNull(eduDailyUserEvaluate.getUserId())
		        		){		            
		        	result.setFalse("关键字段用户ID和日常培训信息ID不能为空");
		            return result;
		        }
//		        eduDailyUserEvaluateMapper.selectByUserIdInfoId();
//主键为空或库中无此主键则为新建，插入数据
		        if(ObjectUtil.isNull(eduDailyUserEvaluate.getId())|| ObjectUtil.isNull(eduDailyUserEvaluateMapper.selectByPrimaryKey(eduDailyUserEvaluate.getId()))){
		        	int res=eduDailyUserEvaluateMapper.insertSelective(eduDailyUserEvaluate);
			        if(res==0){
			            result.setFalse("插入用户评价失败");
			            return result;
			        }
		        }else
		        {
		        	int res=eduDailyUserEvaluateMapper.updateByPrimaryKeySelective(eduDailyUserEvaluate);
		        	 if(res==0){
		        		 result.setFalse("更新用户评价失败");
				         return result;

		        	 }
		        }
		        result.setData(eduDailyUserEvaluate);

		        return result;
		    }


	  
	  public Result delete(int eduDailyUserEvaluateId){
	      Result result=new Result();
	      if(ObjectUtil.isNull(eduDailyUserEvaluateId)){
	          result.setFalse("删除对象不能为空");
	          return result;
	      }
	      int res = eduDailyUserEvaluateMapper.deleteByPrimaryKey(eduDailyUserEvaluateId);
	      if(res==0){
	    	  result.setFalse("删除失败");
		      return result;
	
	      }
	      return result;
	  }

	  
	  public Result find(EduDailyUserEvaluate eduDailyUserEvaluate) {
	      Result result = new Result();
	      PageHelper.startPage(eduDailyUserEvaluate.getPageCurrent(), eduDailyUserEvaluate.getPageSize());
	      List<EduDailyUserEvaluate> eduDailyUserEvaluates = eduDailyUserEvaluateMapper.search(eduDailyUserEvaluate);
	      result.setData(new PageInfo<>(eduDailyUserEvaluates));

	      return result;
	  }
}
